package cn.zhiwen.controller;

import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;

public class poiController {

    public static void main(String[] args) {
        poiDaoRu();
    }

    public static void poiDaoRu() {
        ArrayList<String> vinList = new ArrayList<>();
        try {
            FileInputStream fileInputStream = new FileInputStream("D:\\WorkSpace\\SprngCloud\\springPoi\\src\\main\\resources\\已到达数据7.1~7.31.xlsx");
            //POIFSFileSystem poifsFileSystem = new POIFSFileSystem(fileInputStream);
            //HSSFWorkbook hssfWorkbook = new HSSFWorkbook(poifsFileSystem);
            XSSFWorkbook xssfWorkbook = new XSSFWorkbook(fileInputStream);
            //获取第一个工作簿
            XSSFSheet sheetAt = xssfWorkbook.getSheetAt(0);
            if (sheetAt != null) {
                //获取excel的row 行的数量
                for (int rowNum = 1; rowNum <= sheetAt.getLastRowNum(); rowNum++) {
                    //获取行
                    XSSFRow row = sheetAt.getRow(rowNum);
                    //判断行不是空继续执行
                    if (row == null) {
                        continue;
                    }
                    vinList.add(row.getCell(1).toString());
                    System.out.println(row.getCell(0).toString());
                }
                System.out.println(vinList.size());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
